package com.xuhuan.server.filter;

import com.xuhuan.server.util.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.catalina.connector.RequestFacade;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;
import java.util.Date;

/**
 * @Author huan.xu
 * @Date 2022/6/13 16:40
 * @Description 增加日志
 */
@Slf4j
@WebFilter(urlPatterns = "/*")
public class LogFilter implements Filter {
    @Override
    public void doFilter(
        ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        log.info("{}访问请求：{}", DateUtil.formatDate(new Date(),DateUtil.DATE_TIME_FORMAT),((RequestFacade) servletRequest).getRequestURI());
        filterChain.doFilter(servletRequest,servletResponse);

    }

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void destroy() {

    }
}
